package com.libraryManage.service.impl;

import com.libraryManage.commons.config.Const;
import com.libraryManage.commons.utils.PageUtil;

import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.commons.utils.SimpleResp;
import com.libraryManage.entity.BorrowDo;
import com.libraryManage.mapper.BorrowDoMapper;
import com.libraryManage.service.BorrowService;


import com.libraryManage.vo.BorrowVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author:ZhangQing
 * @Date:2020/11/4
 */

@Service
public class BorrowServiceImpl implements BorrowService {
    @Autowired
    private BorrowDoMapper borrowDoMapper;

    @Override
    public ResponseEntity<List<BorrowDo>> getAllBorrow() {
        PageUtil.startPage(new BorrowVo());
        List<BorrowDo> list = borrowDoMapper.findAll();
        return PageUtil.tranferPage(list);
    }

    @Override
    public BorrowDo getBorrowById(Integer id) {
        BorrowDo borrowDo = borrowDoMapper.selectByPrimaryKey(id);
        return borrowDo;
    }

    @Override
    public SimpleResp insertBorrow(BorrowVo borrowVo) {
        BorrowDo borrowDo = new BorrowDo();
        BeanUtils.copyProperties(borrowVo,borrowDo);
        int res = borrowDoMapper.insert(borrowDo);
        if(res == 1){
            return new SimpleResp(Const.STAT_SUCC,Const.MSG_SUCC);
        }else{
            return new SimpleResp(Const.STAT_SYSERR,Const.MSG_SYSERR);
        }
    }


}
